<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>点击地图拾取坐标</title>
</head>
<script charset="utf-8" src="https://map.qq.com/api/gljs?v=1.exp&key=L6BBZ-SW3W4-R7FUZ-DK6CP-7AVT6-SLBKD"></script>
<style type="text/css">
    html,
    body {
        height: 100%;
        margin: 0px;
        padding: 0px;
    }

    #container {
        width: 100%;
        height: 90%;
    }
    #info{
        position: absolute;
        left: 20px;
        top: 20px;
        font-size: 14px;
        background: #FFF;
        width: 120px;
        padding: 10px;
        border-radius: 3px;
        text-align: center;
    }
    #submit {
        text-align: center;
        padding: 10px;
    }
    #btn-submit{
        font-size: 16px;
        background: #4c51b1;
        border-radius: 5px;
        padding: 4px 10px;
        border: 0;
        color: #fff;
        cursor: pointer;
    }
    .input-latlng {
        border-radius: 5px;
        padding: 5px 10px;
        border: 1px solid #666;
        width: 90px;
    }
</style>

<body onload="initMap()">
<div id="container"></div>
<div id="info">
    点击地图拾取坐标
    <!--<span id="position"></span>-->
</div>
<form id="submit" action="mapPicker" method="post">
    <input name="id" value="{$id}" type="hidden"/>
    <input class="input-latlng" id="lat" name="lat" value="{$lat??''}"/>
    <input class="input-latlng" id="lng" name="lng" value="{$lng??''}"/>
    <button id="btn-submit">选好了</button>
</form>
<script>
  function initMap() {
    var position = document.getElementById("position");

    var center = new TMap.LatLng({$lat??'36.665102'}, {$lng??'117.027799'});//设置中心点坐标
    //初始化地图
    var map = new TMap.Map("container", {
      center: center
    });

    //绑定点击事件
    map.on("click",function(evt){
      var lat = evt.latLng.getLat().toFixed(6);
      var lng = evt.latLng.getLng().toFixed(6);
      // position.innerHTML = lat + "," + lng;
      var input_lat = document.getElementById("lat");
      input_lat.value = lat;
      var input_lng = document.getElementById("lng");
      input_lng.value = lng;
    })
  }
</script>
</body>

</html>